package cn.ly.jmockittest.util;

import cn.ly.jmockittest.Dao;
import cn.ly.jmockittest.LoginDao;
import cn.ly.jmockittest.Service;

import java.lang.reflect.Field;

/**
 * Created by liuyu21 on 2017/10/29.
 */
public class ServiceTool {

    public static void serviceSetter(Service service) throws Exception{
        //2. 获取实例
        LoginDao loginDao = MockTool.getLoginDao();
        Dao dao = MockTool.getDao(Long.valueOf("1"),"admin","admin");

        Field daoField = service.getClass().getDeclaredField("dao");
        daoField.setAccessible(true);
        daoField.set(service,dao);

        Field loginDaoField = service.getClass().getDeclaredField("loginDao");
        loginDaoField.setAccessible(true);
        loginDaoField.set(service,loginDao);
    }

}
